import { plainMatrix } from "../../math/index.js"
import { pointsPath } from "../path.js";
import { _colors } from '../../color/index.js'
import { _g } from "../svg.js";
import { treePoints } from "../../algorithm/tree.js";



// 二叉树
export const _tree = (options, props) => {
    let { depth = 5, color = "none", alpha = 1 } = options
    let ps = treePoints(options)

    // 彩色
    if (color && color !== 'none') {
        let colors = _colors(color, depth + 1, alpha)
        let children = ps.map((t, i) => {
            return pointsPath({
                points: t,
                closed: false,
            }, {
                ...props,
                fill: 'none',
                stroke: colors[i],
            })

        })


        return _g(children)
    } else {
        // 单色
        return pointsPath({
            points: plainMatrix(ps),
            closed: false,
        }, {
            stroke: 'red',
            fill: 'none',
            ...props
        })
    }
}


export const _treeCircle = (options, props) => {
    let { depth = 5, color = "none" } = options
    let ps = treePoints(options)
    // 彩色
    if (color && color !== 'none') {
        let colors = _colors(color, depth + 1, 1)
        let children = ps.map((t, i) => {
            return pointsPath({
                points: t,
                closed: false,
            }, {
                ...props,
                fill: 'none',
                stroke: colors[i],
            })
        })
        return _g(children)
    } else {
        // 单色
        return pointsPath({
            points: plainMatrix(ps),
            closed: false,
        }, {
            stroke: 'red',
            fill: 'none',
            ...props
        })
    }

}